package com.taptech.doufu.ui.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.personalcenter.FlowerOption;

import java.util.List;

public class FlowerOptionAdapter extends BaseAdapter {

    private Context mContext;
    private List<FlowerOption> mList;
    public FlowerOptionAdapter(Context context, List<FlowerOption> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        if (mList != null) {
            return mList.size();
        }
        return 0;
    }

    @Override
    public FlowerOption getItem(int position) {
        if (mList != null && mList.size() > position) {
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FlowerOption model = getItem(position);
        if (model == null) {
            return new View(mContext);
        }
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.flower_option_item, null);
            viewHolder = new ViewHolder();
            viewHolder.tvContent = convertView.findViewById(R.id.tvContent);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        StringBuilder sb = new StringBuilder();
        sb.append(model.getScore()).append("豆子=").append(model.getFlower()).append("朵花");
        viewHolder.tvContent.setText(sb.toString());
        return convertView;
    }


    public static class ViewHolder{
        public TextView tvContent;
    }

}
